export function success(data:any,msg:string) {
    return {
        code:0,
        result:data,
        message:msg
    }
}
export function successPage(res:any,msg:string) {
    return {
        code:0,
        result:res.data,
        ...res.page,
        message:msg
    }
}

export function error(msg:string) {
    return {
        code:-1,
        message:msg
    }
}

export function wrapperResponse(p,msg) {
    return p
    .then((data) => success(data,msg))
    .catch((err) => error(err.message))
}

export function wrapperResponsePage(p,query,msg) {
    const { pageNum,pageSize } = query
    return p
    .then(([data,total]) => {
        const page = {
            pageNum,
            pageSize,
            total
        }
        const result = { data, page }
        return successPage(result,msg)
    })
    .catch((err) => error(err.message))
}
